package com.unitedvision.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.unitedvision.core.domain.Status;
import com.unitedvision.persistence.domain.CompanyCustomerEntity;
import com.unitedvision.persistence.domain.CompanyEntity;
import com.unitedvision.persistence.domain.CustomerEntity;
import com.unitedvision.persistence.repository.CompanyCustomerRepository;
import com.unitedvision.service.CompanyCustomerService;

@Service
public class CompanyCustomerServiceImpl implements CompanyCustomerService {
	@Autowired
	private CompanyCustomerRepository companyCustomerRepository;
	
	@Override
	@Transactional
	public void save(CompanyCustomerEntity entity) {
		companyCustomerRepository.save(entity);
	}

	@Override
	@Transactional
	public void delete(CompanyCustomerEntity entity) {
		companyCustomerRepository.delete(entity);
	}

	@Override
	public void activate(CompanyCustomerEntity entity) {
		entity.setStatus(Status.ACTIVE);
		companyCustomerRepository.save(entity);
	}

	@Override
	public void deactivate(CompanyCustomerEntity entity) {
		entity.setStatus(Status.NONACTIVE);
		companyCustomerRepository.save(entity);
	}

	@Override
	public CompanyCustomerEntity get(int id) {
		return companyCustomerRepository.findOne(id);
	}

	@Override
	public CompanyCustomerEntity getByCustomerCompany(CustomerEntity customer, CompanyEntity company) {
		return companyCustomerRepository.findByCustomerAndCompany(customer, company);
	}

	@Override
	public List<CompanyCustomerEntity> getByCustomer(CustomerEntity customerEntity, Status status) {
		return companyCustomerRepository.findByCustomerAndStatus(customerEntity, status);
	}

	@Override
	public List<CompanyCustomerEntity> getByCompany(CompanyEntity company, Status status) {
		return companyCustomerRepository.findByCompanyAndStatus(company, status);
	}

	@Override
	public List<CompanyCustomerEntity> getAll() {
		return companyCustomerRepository.findAll();
	}

	@Override
	public long count() {
		return companyCustomerRepository.count();
	}
}
